/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wii.elpro.dao.jpa;

import com.wii.elpro.dao.DAOGeneric;
import com.wii.elpro.dao.JPAUtil;
import javax.persistence.EntityManager;

/**
 *
 * @author hendro
 */
public class DAOGenericImpl implements DAOGeneric{

    public void save(Object obj) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            em.persist(obj);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public void update(Object obj) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            em.merge(obj);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public void delete(Object obj) throws Exception {
        JPAUtil.beginTransaction();
        EntityManager em = JPAUtil.getEntityManager();
        try {
            em.remove(obj);
        } catch (Exception ex) {
            throw ex;
        }
    }

}
